# 姓名:刘豹
#  开发时间: 2021/8/12 19:24
from flask_restplus import Api, Resource, Namespace
from flask import make_response, jsonify, send_from_directory, url_for, request, current_app, send_file,Blueprint
from utils.redis_utils import RedisTool,RedisZsetTool
record=Blueprint("record",__name__)
api = Api(record, version='1.0', title='record_API',
          description='温室病虫害用户标记接口')
lb=api.namespace('record', description='用户记录')
# l=RedisStringTool(host='39.102.44.159', port=6379, db=3, password='inetlabredis')
db=RedisZsetTool(host='39.102.44.159', port=6379, db=3, password='inetlabredis')
@lb.route("/get_record/<number>,<int:score>",methods=['POST'])
class GetRecord(Resource):
    def post(self,number='',score=''):
        "获取 用户的评论信息并保存到redis数据库"
        result=db.zsetupdate(number,score)
        return make_response(jsonify({'code': 20000, 'message': 'ok','data':{'result':result}},200))
@lb.route("/check_record/")
class CheckRecord(Resource):
    def get(self):
        "获取保存在数据库中的所有的数据"
        result=db.zsetmread()
        return make_response(jsonify({'code': 20000, 'message': 'ok', 'data': {'result': result}}, 200))
@lb.route("/check_record/<int:score1>,<int:score2>")
class Check_Record(Resource):
    def get(self,score1="",score2=""):
        "查询指定的分数区间的数据"
        result=db.zsetscore(score1,score2)
        return make_response(jsonify({'code': 20000, 'message': 'ok', 'data': {'result': result}}, 200))
@lb.route("/delete_score/<int:min><int:max>")
class Delete_Score(Resource):
    def get(self,min="",max=""):
        "删除指定的分数区间的记录"
        result=db.zsetrangebyscore(min,max)#返回删除的文件的数目
        return make_response(jsonify({'code': 20000, 'message': 'ok', 'data': {'result': result}}, 200))

